package libnetdb.dm.assoc.base;

public abstract class BasicRuleIndex 
        implements RuleIndex, IndexBuilder{
    private String name;
    private String title;
    
    static{
        IndexManager manager = IndexManager.getInstance();
        manager.register(new Confidence());
        manager.register(new Support());
        manager.register(new Interesting());
        manager.register(new ChiSquare());    
    }
    
    protected BasicRuleIndex(String name, String title){
        this.name = name;
        this.title = title;
    }
    
    protected BasicRuleIndex(String name){
        this(name, null);
    }
    
    public String getName(){
        return name;
    }
    
    public String getTitle(){
        return title == null ? name : title;
    }
    
    public String toString(){
        return getTitle();
    }

    private static class Confidence extends BasicRuleIndex{        
                        
        public Confidence(){
            super("Confidence", "Confidence");    
        }
        
        public double getIndex(Rule rule){
            return rule.getConfidence();
        }
        
        public RuleIndex createIndex(){
            return new Confidence();
        }
    }
        
    private static class Support extends BasicRuleIndex{        
        public Support(){
            super("Support", "Support");    
        }
        
        public double getIndex(Rule rule){
            return rule.getSupport();
        }

        public RuleIndex createIndex(){
            return new Support();
        }
    }

    private static class Interesting extends BasicRuleIndex{        
        public Interesting(){
            super("Interesting", "Interesting");    
        }
        
        public double getIndex(Rule rule){
            return rule.getInteresting();
        }
        
        public RuleIndex createIndex(){
            return new Interesting();
        }        
    }

    private static class ChiSquare extends BasicRuleIndex{        
        public ChiSquare(){
            super("ChiSquare", "Chi Square");    
        }
        
        public double getIndex(Rule rule){
            return rule.getChiSquare();
        }

        public RuleIndex createIndex(){
            return new ChiSquare();
        }        
    }
}

    